home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrMultiMap<K,T,C> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpmmap.h> RWTPtrMultiMap<K,T,C> m; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of associations of type ppppaaaaiiiirrrr<<<<KKKK****,,,, ccccoooonnnnsssstttt TTTT****>>>>. The first part of the association is a key of type KKKK****, the second is its associated item of type TTTT****. Order is determined by the key according to a comparison object of type CCCC. CCCC must induce a total ordering on elements of type KKKK via a public member bool operator()(const K& x, const K& y) which returns ttttrrrruuuueeee if xxxx and its partner should precede yyyy and its partner within the collection. The structure lllleeeessssssss<<<<TTTT>>>> from the C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an example. Note that keys will be dereferenced before being compared. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> may contain multiple keys that compare equal to each other. (RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> will not accept a key that compares equal to any key already in the collection.) Equality is based on the comparison object and not on the ======== operator. Given a comparison object ccccoooommmmpppp, keys aaaa and bbbb are equal if !comp(a,b) && !comp(b,a). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic. EEEExxxxaaaammmmpppplllleeeessss In this example, a multimap of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs and RRRRWWWWDDDDaaaatttteeees is exercised. PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) // // tpmmap.cpp // #include <rw/tpmmap.h> #include <rw/cstring.h> #include <rw/rwdate.h> #include <iostream.h> main(){ typedef RWTPtrMultiMap<RWCString, RWDate, less<RWCString> > RWMMap; RWMMap birthdays; birthdays.insert(new RWCString("John"), new RWDate(12, "April", 1975)); birthdays.insert(new RWCString("Ivan"), new RWDate(2, "Nov", 1980)); birthdays.insert(new RWCString("Mary"), new RWDate(22, "Oct", 1987)); birthdays.insert(new RWCString("Ivan"), new RWDate(19, "June", 1971)); birthdays.insert(new RWCString("Sally"), new RWDate(15, "March", 1976)); birthdays.insert(new RWCString("Ivan"), new RWDate(6, "July", 1950)); // How many "Ivan"s? RWCString ivanstr("Ivan"); RWMMap::size_type n = birthdays.occurrencesOf(&ivanstr); RWMMap::size_type idx = 0; cout << "There are " << n << " Ivans:" << endl; RWMMap::const_iterator iter = birthdays.std().lower_bound(&ivanstr); while (++idx <= n) cout << idx << ". " << *(*iter++).second << endl; return 0; } PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Program Output: There are 3 Ivans: 1. 11/02/80 2. 06/19/71 3. 07/06/50 RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss Class RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> offers the same interface to a pointer-based collection that will not accept multiple keys that compare equal to each other. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> maintains a pointer-based collection of keys without the associated values. Class mmmmuuuullllttttiiiimmmmaaaapppp<<<<KKKK****,,,,TTTT****,,,,ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<CCCC,,,,KKKK,,,,aaaallllllllooooccccaaaattttoooorrrr>>>> >>>> is the C++-standard collection that serves as the underlying implementation for this collection. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_deref_compare<C,K> container_comp; typedef multimap<K*,T*,container_comp,allocator> container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef pair<K* const, T*> value_type; typedef pair<K* const, T*> reference; typedef const pair<K* const, T*>& const_reference; typedef K* value_type_key; typedef T* value_type_data; typedef K*& reference_key; typedef T*& reference_data; typedef const K*const& const_reference_key; typedef const T*const& const_reference_data; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> (const container_comp& comp =container_comp()); Constructs an empty map with comparator ccccoooommmmpppp. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const container_type& m); Constructs a multimap by copying all element from mmmm. RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const RWTPtrMultiMap<K,T,C>& rwm); Copy constructor. PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(value_type* first,value_type* last, const container_comp& comp = container_comp()); Constructs a multimap by copying elements from the array of ppppaaaaiiiirrrrs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the pair pointed to by llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrMultiMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type& m); RWTPtrMultiMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrMultiMap<K,T,C>& m); Destroys all associations in self and replaces them by copying all associations from mmmm.... bool ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTPtrMultiMap<K,T,C>& m); Returns ttttrrrruuuueeee if self compares lexicographically less than mmmm, otherwise returns ffffaaaallllsssseeee. Keys in each collection are dereferenced before being compared. Assumes that type KKKK has well-defined less-than semantics. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrMultiMap<K,T,C>& m); Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual keys that compare equal to each other. Keys are dereferenced before being compared. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K*,const T*,void*),void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. This function must have one of the prototypes: void yourfun(const K* key, T*& a, void* d); void yourfun(const K* key, const T* a, void* d); PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Client data may be passed through parameter dddd. void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K*, T*&,void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K*,const T*,void*),void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first pair in self. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all associations from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by the keys and their associated items. Do not use this method if multiple pointers to the same object are stored. bool ccccoooonnnnttttaaaaiiiinnnnssss(const K* key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(value_type,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an association a in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of associations in self. const K* ffffiiiinnnndddd(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, then jjjj is returned. Otherwise, returns rrrrwwwwnnnniiiillll. value_type ffffiiiinnnndddd(bool (*fn)(value_type,void*), void* d) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, then returns aaaa. Otherwise, returns ppppaaaaiiiirrrr<<<<rrrrwwwwnnnniiiillll,,,,rrrrwwwwnnnniiiillll>>>>. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key); const T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key) const; PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) If there exists a key jjjj in self such that the expression ((((****jjjj ======== ****kkkkeeeeyyyy)))) is ttttrrrruuuueeee, returns the item associated with jjjj. Otherwise, returns rrrrwwwwnnnniiiillll. const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, T*& tr); const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, const T*& tr) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, assigns the item associated with jjjj to ttttrrrr,,,, and returns jjjj. Otherwise, returns rrrrwwwwnnnniiiillll and leaves the value of ttttrrrr unchanged. bool iiiinnnnsssseeeerrrrtttt(K* key, T* a); Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(K* key, T* a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K* key) const; Returns the number of keys jjjj in self that compare equal to ****kkkkeeeeyyyy. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool (*fn)(value_type,void*), void* d) const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) Client data may be passed through parameter dddd. K* rrrreeeemmmmoooovvvveeee(const K* key); Removes the first association with key jjjj in self such that the expression ((((****jjjj ======== ****kkkkeeeeyyyy)))) is ttttrrrruuuueeee and returns jjjj. Returns rrrrwwwwnnnniiiillll if there is no such association. K* rrrreeeemmmmoooovvvveeee(bool (*fn)(value_type,void*), void* d); Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns its key. Returns rrrrwwwwnnnniiiillll if there is no such association. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K* key); Removes all associations with key jjjj in self that compare equal to ****kkkkeeeeyyyy. Returns the number of associations removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(value_type,void*), void* d); Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number removed. ffffnnnn points to a user- defined tester function which must have prototype: bool yourTester(value_type a, void* d); Client data may be passed through parameter dddd. PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp((((3333CCCC++++++++)))) container_type& ssssttttdddd(); const container_type& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrMultiMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrMultiMap<K,T,C>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMultiMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMultiMap<K,T,C>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMultiMap<K,T,C>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMultiMap<K,T,C>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999